package main;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class Secondchance {
	
	public static Queue<Page> fifo = new LinkedList<Page>();
	public static int QUEUE_SIZE = 7;
	
	public static void add(Page page){
		
		if(fifo.size() <= QUEUE_SIZE){
			fifo.add(page);
		}else{
			remove();
			add(page);
		}
		
	} 
	
	public static void remove(){
		
		if(fifo.isEmpty()){
		
			System.out.println("queue is empty");
			
		} else {
			
			if(fifo.peek().r == 0){
				
				fifo.remove();
			} else {
				Page head_page = fifo.poll();
				head_page.r = 0;
				fifo.add(head_page);
				remove();
			}
		}
	}
}
